home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / TCCLIB.ZIP / COPYFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-07  |  625 b   |  35 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <alloc.h>
  4. #include <io.h>
  5.  
  6. int CopyFile( char *src, char *dest )
  7. {
  8.     int fd1, fd2, num;
  9.     char *buffer;
  10.  
  11.     if ( ( buffer = (char *) calloc( 32001, 1 ) ) == NULL ) {
  12.         return( -1 );
  13.     }
  14.  
  15.     if ( ( fd1 = open( src, O_RDONLY | O_BINARY ) ) == EOF ) {
  16.         free( buffer );
  17.         return( -2 );
  18.     }
  19.  
  20.     if ( ( fd2 = _creat( dest, 0 ) ) == EOF ) {
  21.         free( buffer );
  22.         return( -3 );
  23.     }
  24.  
  25.     while ( ( num = read( fd1, buffer, 32000 ) ) > 0 ) {
  26.         if ( num != write( fd2, buffer, num ) )
  27.             return( -4 );
  28.     }
  29.  
  30.     close( fd2 );
  31.     close( fd1 );
  32.     free( buffer );
  33.     return( 0 );
  34. }
  35.